<template>
  <div class="wecom-user-container">
    <!-- 文档提示 -->
    <div class="doc-alerts">
      <doc-alert title="用户体系" url="https://doc.iocoder.cn/user-center/" />
      <doc-alert title="三方登陆" url="https://doc.iocoder.cn/social-user/" />
      <doc-alert title="Excel 导入导出" url="https://doc.iocoder.cn/excel-import-and-export/" />
    </div>

    <el-row :gutter="20" class="main-row">
      <el-col :span="24" :xs="24">
        <!-- 搜索区域 -->
        <ContentWrap class="search-wrapper">
          <!-- 搜索头部 -->
          <div class="search-header">
            <div class="header-icon">
              <Icon icon="ep:user" />
            </div>
            <div class="header-content">
              <h3 class="search-title">企微用户管理</h3>
              <p class="search-subtitle">管理企业微信用户信息和绑定状态</p>
            </div>
          </div>

          <!-- 搜索表单 -->
          <div class="search-form-container">
            <el-form
              :model="queryParams"
              ref="queryFormRef"
              :inline="true"
              label-position="left"
              label-width="100px"
              class="enhanced-search-form"
            >
              <div class="form-grid">
                <el-form-item label="登录账号" prop="weUserId" class="form-item">
                  <el-input
                    v-model="queryParams.weUserId"
                    placeholder="请输入登录账号"
                    clearable
                    @keyup.enter="handleQuery"
                    class="enhanced-input"
                  >
                    <template #prefix>
                      <Icon icon="ep:user" />
                    </template>
                  </el-input>
                </el-form-item>

                <el-form-item label="绑定状态" prop="bindStatus" class="form-item">
                  <el-select
                    v-model="queryParams.bindStatus"
                    placeholder="CRM账号绑定状态"
                    clearable
                    class="enhanced-select"
                  >
                    <template #prefix>
                      <Icon icon="ep:link" />
                    </template>
                    <el-option :key="0" label="未绑定" :value="0" />
                    <el-option :key="1" label="已绑定" :value="1" />
                  </el-select>
                </el-form-item>

                <el-form-item label="创建时间" prop="createTime" class="form-item">
                  <el-date-picker
                    v-model="queryParams.createTime"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    type="datetimerange"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    class="enhanced-date-picker"
                  />
                </el-form-item>
              </div>

              <div class="form-actions">
                <el-button @click="handleQuery" class="search-btn">
                  <Icon icon="ep:search" class="btn-icon" />
                  搜索
                </el-button>
                <el-button @click="resetQuery" class="reset-btn">
                  <Icon icon="ep:refresh" class="btn-icon" />
                  重置
                </el-button>
                <el-button type="primary" plain @click="handleSyncUser" class="sync-btn">
                  <Icon icon="ep:switch" class="btn-icon" />
                  同步企微账号
                </el-button>
              </div>
            </el-form>
          </div>
        </ContentWrap>

        <!-- 表格区域 -->
        <ContentWrap class="table-wrapper">
          <div class="table-container">
            <el-table
              v-loading="loading"
              :data="list"
              class="enhanced-table"
              :header-cell-style="{ background: '#f8f9ff', color: '#303133', fontWeight: '600' }"
            >
              <el-table-column
                label="企微用户ID"
                align="center"
                prop="weUserId"
                :show-overflow-tooltip="true"
                min-width="150"
              >
                <template #default="scope">
                  <div class="user-id-cell">
                    <Icon icon="ep:postcard" class="cell-icon" />
                    <span class="masked-id">{{ maskString(scope.row.weUserId) }}</span>
                  </div>
                </template>
              </el-table-column>

              <el-table-column label="CRM账号绑定状态" prop="bindStatus" align="center" width="180">
                <template #default="scope">
                  <el-tag v-if="scope.row.bindStatus" type="success" class="status-tag success-tag">
                    <Icon icon="ep:check" class="tag-icon" />
                    已绑定
                  </el-tag>
                  <el-tag v-else type="info" class="status-tag info-tag">
                    <Icon icon="ep:close" class="tag-icon" />
                    未绑定
                  </el-tag>
                </template>
              </el-table-column>

              <el-table-column
                label="绑定的用户"
                align="center"
                prop="nickname"
                :show-overflow-tooltip="true"
                min-width="180"
              >
                <template #default="scope">
                  <div class="user-info-cell">
                    <div class="user-avatar">
                      <img
                        v-if="scope.row.avatar"
                        :src="scope.row.avatar"
                        class="avatar-img"
                        alt="用户头像"
                      />
                      <div v-else class="avatar-placeholder">
                        <Icon icon="ep:user" />
                      </div>
                    </div>
                    <span class="user-name">{{ scope.row.nickname || '-' }}</span>
                  </div>
                </template>
              </el-table-column>

              <el-table-column
                label="客户数量"
                align="center"
                prop="customerCount"
                :show-overflow-tooltip="true"
                width="140"
              >
                <template #default="scope">
                  <el-link
                    @click="showCustomerDialog(scope.row.customerCount, scope.row)"
                    type="primary"
                    class="count-link"
                  >
                    <Icon icon="ep:user-filled" class="link-icon" />
                    {{ scope.row.customerCount || 0 }}
                  </el-link>
                </template>
              </el-table-column>

              <el-table-column
                label="群聊数量"
                align="center"
                prop="chatGroupCount"
                :show-overflow-tooltip="true"
                width="140"
              >
                <template #default="scope">
                  <el-link
                    @click="showChatDialog(scope.row.chatGroupCount, scope.row)"
                    type="primary"
                    class="count-link"
                  >
                    <Icon icon="ep:chat-dot-round" class="link-icon" />
                    {{ scope.row.chatGroupCount || 0 }}
                  </el-link>
                </template>
              </el-table-column>

              <el-table-column
                label="获客链接数量"
                align="center"
                prop="acqLinkCount"
                :show-overflow-tooltip="true"
                width="140"
              >
                <template #default="scope">
                  <el-link
                    @click="showLinkDialog(scope.row.acqList)"
                    type="primary"
                    class="count-link"
                  >
                    <Icon icon="ep:link" class="link-icon" />
                    {{ scope.row.acqList?.length || 0 }}
                  </el-link>
                </template>
              </el-table-column>

              <el-table-column
                label="创建时间"
                align="center"
                prop="createTime"
                :formatter="dateFormatter"
                width="200"
              >
                <template #default="scope">
                  <div class="time-cell">
                    <Icon icon="ep:clock" class="time-icon" />
                    <span>{{ dateFormatter(scope.row, null, scope.row.createTime) }}</span>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>

          <!-- 分页 -->
          <div class="pagination-wrapper">
            <Pagination
              :total="total"
              v-model:page="queryParams.pageNo"
              v-model:limit="queryParams.pageSize"
              @pagination="getList"
            />
          </div>
        </ContentWrap>
      </el-col>
    </el-row>

    <!-- 客户列表弹窗 -->
    <Dialog
      v-model="customerDialogVisible"
      title="客户列表"
      width="1600"
      :lock-scroll="false"
      class="enhanced-dialog"
    >
      <ContentWrap>
        <div class="dialog-table-container">
          <el-table
            border
            :header-cell-style="{ background: '#f8f9ff', color: '#303133', fontWeight: '600' }"
            :data="customerTableData"
            stripe
            max-height="600"
            class="dialog-table"
          >
            <el-table-column label="客户名称" align="center" prop="name">
              <template #default="scope">
                <span @click="goDetail(scope.row)" class="customer-name-link">
                  <Icon icon="ep:user" class="name-icon" />
                  {{ scope.row.name }}
                </span>
              </template>
            </el-table-column>
            <el-table-column
              label="客户所在企业"
              align="center"
              prop="corpName"
              show-overflow-tooltip
            />
            <el-table-column
              label="客户所在企业主体"
              align="center"
              prop="corpFullName"
              show-overflow-tooltip
            />
            <el-table-column label="客户职位" align="center" prop="positionName" />
            <el-table-column label="客户备注" align="center" prop="remark" />
            <el-table-column label="客户描述" align="center" prop="description" />
            <el-table-column label="备注的手机号" align="center" prop="remarkMobiles" />
            <el-table-column
              label="上次聊天时间"
              align="center"
              prop="lastChatTime"
              :formatter="dateFormatter"
            />
            <el-table-column
              label="创建时间"
              align="center"
              prop="createTime"
              width="200px"
              :formatter="dateFormatter"
            />
          </el-table>
        </div>
        <div class="dialog-pagination">
          <Pagination
            layout="total,prev, pager, next,jumper"
            :total="totals"
            v-model:page="paramsPage.pageNo"
            v-model:limit="paramsPage.pageSize"
            @pagination="nextCustomerPage"
          />
        </div>
      </ContentWrap>
    </Dialog>

    <!-- 群聊列表弹窗 -->
    <Dialog
      v-model="chatDialogVisible"
      title="群聊列表"
      width="1200"
      :lock-scroll="false"
      class="enhanced-dialog"
    >
      <ContentWrap>
        <div class="dialog-table-container">
          <el-table
            border
            :header-cell-style="{ background: '#f8f9ff', color: '#303133', fontWeight: '600' }"
            :data="chatTableData"
            stripe
            max-height="600"
            class="dialog-table"
          >
            <el-table-column label="群聊名称" align="center" prop="name" width="180" />
            <el-table-column label="群主" align="center" prop="ownerNickname" width="100" />
            <el-table-column label="群公告" align="center" prop="notice">
              <template #default="scope">
                <div class="notice-content">
                  {{ scope.row.notice }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              label="上次聊天时间"
              align="center"
              prop="lastChatTime"
              width="180px"
              :formatter="dateFormatter"
            />
            <el-table-column
              label="创建时间"
              align="center"
              prop="createTime"
              width="200px"
              :formatter="dateFormatter"
            />
          </el-table>
        </div>
        <div class="dialog-pagination">
          <Pagination
            layout="total,prev, pager, next,jumper"
            :total="totals"
            v-model:page="paramsPage.pageNo"
            v-model:limit="paramsPage.pageSize"
            @pagination="nextChatPage"
          />
        </div>
      </ContentWrap>
    </Dialog>

    <!-- 获客链接列表弹窗 -->
    <Dialog
      v-model="linkDialogVisible"
      title="获客链接列表"
      width="1600"
      :lock-scroll="false"
      class="enhanced-dialog"
    >
      <div class="dialog-table-container">
        <el-table
          border
          :header-cell-style="{ background: '#f8f9ff', color: '#303133', fontWeight: '600' }"
          :data="linkTableData"
          stripe
          max-height="600"
          class="dialog-table"
        >
          <el-table-column label="企微获客链接名称" align="left" prop="weLinkName" width="250" />
          <el-table-column label="获客链接地址" align="center" prop="weLinkUrl" width="500">
            <template #default="scope">
              <div class="link-cell">
                <el-link :href="scope.row.weLinkUrl" target="_blank" class="link-url">
                  {{ scope.row.weLinkUrl }}
                </el-link>
                <div class="link-actions">
                  <el-button
                    size="small"
                    @click="copyQrcode(scope.row.weLinkUrl)"
                    type="success"
                    class="action-btn"
                  >
                    <Icon icon="ep:document-copy" class="btn-icon" />
                    复制链接
                  </el-button>
                  <el-button
                    size="small"
                    @click="checkQrcode(scope.row.weLinkUrl)"
                    type="primary"
                    class="action-btn"
                  >
                    <Icon icon="ep:view" class="btn-icon" />
                    查看二维码
                  </el-button>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="近30天点击次数" align="center">
            <template #default="scope">
              <div class="stat-cell">
                <Icon icon="ep:mouse" class="stat-icon" />
                <span>{{ useStat[scope.row.weLinkId]?.clickCount ?? '--' }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="近30天新增客户" align="center">
            <template #default="scope">
              <div class="stat-cell">
                <Icon icon="ep:user-filled" class="stat-icon" />
                <span>{{ useStat[scope.row.weLinkId]?.newCount ?? '--' }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="创建时间"
            align="center"
            prop="createTime"
            :formatter="dateFormatter"
            width="200"
          />
        </el-table>
      </div>
    </Dialog>

    <DetailDrawer ref="detailRef" />

    <!-- 二维码弹窗 -->
    <Dialog
      title="二维码"
      v-model="qrCodeVisible"
      width="350px"
      append-to-body
      :close-on-press-escape="false"
      class="qrcode-dialog"
    >
      <div class="qrcode-container">
        <Qrcode id="qr_code" @done="onCodeDone" :text="qrCodeLink" :width="310" />
        <div class="qrcode-actions">
          <el-button @click="downloadQrcode" type="primary" class="download-btn">
            <Icon icon="ep:download" class="btn-icon" />
            下载二维码
          </el-button>
        </div>
      </div>
    </Dialog>
  </div>
</template>

<script lang="ts" setup>
import { dateFormatter } from '@/utils/formatTime'
import * as WecomUserApi from '@/api/wecom/user/index'
import DetailDrawer from '../customer/DetailDrawer.vue'
import { Qrcode } from '@/components/Qrcode'
import { useClipboard } from '@vueuse/core'
import * as AcqLinkApi from '@/api/wecom/acqlink'
import * as apiConfig from '@/api/wecom/apiconfig/index'
import { getWeChatGroupPage } from '@/api/wecom/chatgroup/index'

defineOptions({ name: 'WecomWeUser' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  weUserId: undefined,
  bindStatus: undefined,
  createTime: [],
  showCount: true
})
const queryFormRef = ref() // 搜索的表单

/*弹窗分页*/
const totals = ref(0)
const paramsPage = reactive({
  pageNo: 1,
  pageSize: 10
})

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await WecomUserApi.getWeUserPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields()
  handleQuery()
}

const StatusMap = {
  1: '已激活',
  2: '已禁用',
  4: '未激活',
  5: '退出企业'
}

/** 同步企微员工 */
const handleSyncUser = async () => {
  const data = await WecomUserApi.syncUser()
  if (data) {
    message.success(t('同步成功'))
    await getList()
  } else {
    message.error(t('同步有误'))
  }
}

/** 客户数量 */
const customerDialogVisible = ref(false)
const customerWeUserId = ref(null)
const customerTableData = ref([])
/*客户数量分页*/
const nextCustomerPage = async (val) => {
  paramsPage.pageNo = val.page
  const { list, total } = await apiConfig.listByUser({
    qwUserId: customerWeUserId.value,
    ...paramsPage
  })
  customerTableData.value = list
  totals.value = total
}
/*客户数量dialog*/
const showCustomerDialog = async (customerCount, item) => {
  if (customerCount == 0) return
  paramsPage.pageNo = 1
  customerDialogVisible.value = true
  customerWeUserId.value = item.weUserId
  const { list, total } = await apiConfig.listByUser({ qwUserId: item.weUserId, ...paramsPage })
  customerTableData.value = list
  totals.value = total
}

/** 群聊数量 */
const chatDialogVisible = ref(false)
const chatTableData = ref([])
/*群聊分页*/
const nextChatPage = async (val) => {
  paramsPage.pageNo = val.page
  const { list, total } = await getWeChatGroupPage({
    weUserId: customerWeUserId.value,
    ...paramsPage,
    isAll: 1
  })
  chatTableData.value = list
  totals.value = total
}
/*群聊数量dialog*/
const showChatDialog = async (chatGroupCount, item) => {
  if (chatGroupCount == 0) return
  paramsPage.pageNo = 1
  chatDialogVisible.value = true
  customerWeUserId.value = item.weUserId
  const { list, total } = await getWeChatGroupPage({
    weUserId: item.weUserId,
    ...paramsPage,
    isAll: 1
  })
  chatTableData.value = list
  totals.value = total
}

/** 获客链接数量 */
const weLinkIds = ref([])
const useStat = ref({})
const linkDialogVisible = ref(false)
const linkTableData = ref([])
const showLinkDialog = async (ids) => {
  if (ids.length == 0) return
  linkDialogVisible.value = true
  const data = await WecomUserApi.getByLinkIdList(ids)
  linkTableData.value = data
  linkTableData.value.map((i) => {
    weLinkIds.value.push(i.weLinkId)
  })
  useStat.value = await AcqLinkApi.getUseStat({
    weLinkIds: weLinkIds.value
  })
}
const detailRef = ref(null)
/** 详情 */
const goDetail = (item) => {
  customerDialogVisible.value = false
  detailRef.value.open(true, item)
}

/** 查看二维码 */
const qrCodeVisible = ref(false)
const qrCodeLink = ref(null)
const checkQrcode = (link) => {
  qrCodeLink.value = link
  qrCodeVisible.value = true
}
const qrCodeValue = ref()
const onCodeDone = (e) => {
  qrCodeValue.value = e
}
/** 复制 */
const copyQrcode = async (link) => {
  const { copy, copied, isSupported } = useClipboard({ source: link })
  if (!isSupported) {
    message.error(t('common.copyError'))
    return
  }
  await copy()
  if (unref(copied)) {
    message.success(t('common.copySuccess'))
  }
}

/** 下载二维码 */
const downloadQrcode = () => {
  let save = document.createElement('a')
  save.href = qrCodeValue.value
  // 下载的名字
  save.download = '获客链接二维码.png'
  // 直接回调a的点击事件
  save.click()
}
/*处理id*/
const maskString = (str) => {
  if (str.length !== 32) {
    return str
  }
  const start = str.slice(0, 3)
  const end = str.slice(-3)
  return `${start}******${end}`
}
/** 初始化 */
onMounted(() => {
  getList()
})
</script>

<style lang="scss" scoped>
// 主题色变量
$primary-color: #0052cc;
$primary-light: rgba(0, 82, 204, 0.1);
$primary-border: rgba(0, 82, 204, 0.3);
$success-color: #67c23a;
$warning-color: #e6a23c;
$danger-color: #f56c6c;
$info-color: #909399;
$text-primary: #303133;
$text-regular: #606266;
$text-secondary: #909399;
$text-placeholder: #c0c4cc;
$border-color: #dcdfe6;
$border-light: #e4e7ed;
$bg-color: #f5f7fa;
$shadow-light: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
$shadow-base:
  0 2px 4px rgba(0, 0, 0, 0.12),
  0 0 6px rgba(0, 0, 0, 0.04);
$border-radius: 12px;
$border-radius-small: 8px;

.wecom-user-container {
  padding: 16px;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;

  @media (max-width: 768px) {
    padding: 8px;
  }
}

/* 文档提示区域 */
.doc-alerts {
  margin-bottom: 16px;

  @media (max-width: 768px) {
    margin-bottom: 12px;
  }
}

.main-row {
  @media (max-width: 768px) {
    margin: 0 !important;
  }
}

/* 搜索区域样式 */
.search-wrapper {
  margin-bottom: 16px;
  border-radius: $border-radius;
  overflow: hidden;
  box-shadow: $shadow-light;
  border: 1px solid $border-light;

  :deep(.el-card__body) {
    padding: 0;
  }
}

.search-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  color: white;
  border-bottom: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px;
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
}

.header-icon {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: $border-radius-small;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;

  @media (max-width: 768px) {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}

.header-content {
  flex: 1;
  margin-left: 16px;

  @media (max-width: 768px) {
    margin-left: 0;
  }
}

.search-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 18px;
  }
}

.search-subtitle {
  font-size: 14px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

.search-form-container {
  background: white;
  padding: 24px;

  @media (max-width: 768px) {
    padding: 16px;
  }
}

.enhanced-search-form {
  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 20px;

    @media (max-width: 768px) {
      grid-template-columns: 1fr;
      gap: 16px;
    }
  }

  .form-item {
    margin-bottom: 0;

    :deep(.el-form-item__label) {
      font-weight: 500;
      color: $text-regular;
    }
  }
}

.enhanced-input,
.enhanced-select,
.enhanced-date-picker {
  width: 100%;

  :deep(.el-input__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
    }
  }
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;

  @media (max-width: 768px) {
    flex-direction: column;
  }
}

.search-btn {
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  border: none;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  color: white;
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.reset-btn {
  border: 2px solid $border-color;
  color: $text-regular;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    border-color: $primary-color;
    color: $primary-color;
    background: $primary-light;
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.sync-btn {
  border: 2px solid $primary-color;
  color: $primary-color;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    background: $primary-light;
    transform: translateY(-1px);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

/* 表格区域样式 */
.table-wrapper {
  border-radius: $border-radius;
  overflow: hidden;
  box-shadow: $shadow-light;
  border: 1px solid $border-light;

  :deep(.el-card__body) {
    padding: 0;
  }
}

.table-container {
  background: white;
  overflow-x: auto;
}

.enhanced-table {
  :deep(.el-table__header) {
    th {
      background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%) !important;
      color: $text-primary !important;
      font-weight: 600 !important;
      border-bottom: 2px solid $primary-light;
      padding: 16px 12px;
    }
  }

  :deep(.el-table__body) {
    tr {
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light !important;
      }

      td {
        padding: 14px 12px;
        border-bottom: 1px solid $border-light;
        color: $text-regular;
        font-size: 13px;
      }
    }

    .el-table__row--striped {
      background: #fafbff;

      &:hover {
        background: $primary-light !important;
      }
    }
  }

  // H5适配
  @media (max-width: 768px) {
    :deep(.el-table__header) th {
      padding: 12px 8px;
      font-size: 13px;
    }

    :deep(.el-table__body) td {
      padding: 12px 8px;
      font-size: 12px;
    }
  }
}

/* 表格单元格样式 */
.user-id-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.cell-icon {
  color: $primary-color;
  font-size: 14px;
  flex-shrink: 0;
}

.masked-id {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: $text-regular;
  background: #f5f7fa;
  padding: 2px 6px;
  border-radius: 4px;
}

.status-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 12px;
  padding: 4px 8px;

  .tag-icon {
    font-size: 12px;
  }

  &.success-tag {
    background: rgba(103, 194, 58, 0.1);
    border-color: rgba(103, 194, 58, 0.3);
    color: $success-color;
  }

  &.info-tag {
    background: rgba(144, 147, 153, 0.1);
    border-color: rgba(144, 147, 153, 0.3);
    color: $info-color;
  }
}

.user-info-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.user-avatar {
  flex-shrink: 0;
}

.avatar-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: $shadow-base;

  @media (max-width: 768px) {
    width: 32px;
    height: 32px;
  }
}

.avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: $primary-light;
  display: flex;
  align-items: center;
  justify-content: center;
  color: $primary-color;
  font-size: 16px;
  box-shadow: $shadow-base;

  @media (max-width: 768px) {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
}

.user-name {
  font-weight: 500;
  color: $text-primary;
}

.count-link {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  transition: all 0.3s ease;

  &:hover {
    transform: scale(1.05);
  }

  .link-icon {
    font-size: 12px;
  }
}

.time-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  font-size: 12px;
  color: $text-secondary;
}

.time-icon {
  color: $text-secondary;
  font-size: 14px;
}

/* 分页样式 */
.pagination-wrapper {
  display: flex;
  justify-content: center;
  padding: 20px 24px;
  background: white;
  border-top: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px;
  }

  :deep(.el-pagination) {
    .el-pager li {
      border-radius: 6px;
      margin: 0 2px;
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light;
        color: $primary-color;
      }

      &.is-active {
        background: $primary-color;
        color: white;
      }
    }

    .btn-prev,
    .btn-next {
      border-radius: 6px;
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light;
        color: $primary-color;
      }
    }

    @media (max-width: 768px) {
      .el-pagination__sizes,
      .el-pagination__jump {
        display: none;
      }
    }
  }
}

/* 弹窗样式 */
.enhanced-dialog {
  :deep(.el-dialog) {
    border-radius: $border-radius;
    overflow: hidden;
  }

  :deep(.el-dialog__header) {
    background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
    color: white;
    padding: 20px 24px;
  }

  :deep(.el-dialog__title) {
    color: white;
    font-weight: 600;
  }

  :deep(.el-dialog__headerbtn) {
    .el-dialog__close {
      color: white;
      font-size: 18px;

      &:hover {
        color: rgba(255, 255, 255, 0.8);
      }
    }
  }

  :deep(.el-dialog__body) {
    padding: 0;
  }
}

.dialog-table-container {
  background: white;
  overflow-x: auto;
}

.dialog-table {
  :deep(.el-table__header) {
    th {
      background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%) !important;
      color: $text-primary !important;
      font-weight: 600 !important;
      border-bottom: 2px solid $primary-light;
    }
  }

  :deep(.el-table__body) {
    tr {
      &:hover {
        background: $primary-light !important;
      }
    }
  }
}

.customer-name-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: $primary-color;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    color: darken($primary-color, 10%);
    transform: scale(1.02);
  }

  .name-icon {
    font-size: 14px;
  }
}

.link-cell {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-url {
  word-break: break-all;
  font-size: 12px;
}

.link-actions {
  display: flex;
  gap: 8px;
  justify-content: center;

  @media (max-width: 768px) {
    flex-direction: column;
    gap: 4px;
  }
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.3s ease;

  &:hover {
    transform: scale(1.05);
  }

  .btn-icon {
    font-size: 12px;
  }
}

.stat-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  font-weight: 500;
}

.stat-icon {
  color: $primary-color;
  font-size: 14px;
}

.dialog-pagination {
  padding: 16px 24px;
  background: white;
  border-top: 1px solid $border-light;
  display: flex;
  justify-content: center;

  @media (max-width: 768px) {
    padding: 12px 16px;
  }
}

/* 二维码弹窗 */
.qrcode-dialog {
  :deep(.el-dialog) {
    border-radius: $border-radius;
  }

  :deep(.el-dialog__header) {
    background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
    color: white;
    padding: 16px 20px;
  }

  :deep(.el-dialog__title) {
    color: white;
    font-weight: 600;
  }

  :deep(.el-dialog__headerbtn) {
    .el-dialog__close {
      color: white;

      &:hover {
        color: rgba(255, 255, 255, 0.8);
      }
    }
  }
}

.qrcode-container {
  text-align: center;
  padding: 20px;
}

.qrcode-actions {
  margin-top: 16px;
}

.download-btn {
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  border: none;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
  }

  .btn-icon {
    margin-right: 6px;
  }
}

/* 通用样式 */
.break-word {
  word-break: break-all;
  overflow-wrap: break-word;
}

.notice-content {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
  max-height: 6em;
}

/* 响应式优化 */
@media (max-width: 480px) {
  .wecom-user-container {
    padding: 4px;
  }

  .search-form-container {
    padding: 12px;
  }

  .enhanced-search-form {
    .form-grid {
      gap: 12px;
    }

    .form-item {
      :deep(.el-form-item__label) {
        width: 80px !important;
        font-size: 13px;
      }
    }
  }

  .form-actions {
    gap: 8px;

    .el-button {
      padding: 8px 12px;
      font-size: 13px;
    }
  }

  .enhanced-table {
    :deep(.el-table__header) th {
      padding: 10px 6px;
      font-size: 12px;
    }

    :deep(.el-table__body) td {
      padding: 10px 6px;
      font-size: 11px;
    }
  }

  .avatar-img,
  .avatar-placeholder {
    width: 28px;
    height: 28px;
  }

  .pagination-wrapper {
    padding: 12px;
  }

  .dialog-pagination {
    padding: 8px 12px;
  }
}

/* 加载状态优化 */
:deep(.el-loading-mask) {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(2px);

  .el-loading-spinner {
    .path {
      stroke: $primary-color;
    }
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .wecom-user-container {
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  }

  .search-wrapper,
  .table-wrapper {
    background: #374151;
    border-color: #4b5563;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .search-form-container,
  .table-container,
  .pagination-wrapper {
    background: #374151;
  }

  .search-title {
    color: #f9fafb;
  }

  .user-name {
    color: #f9fafb;
  }

  .enhanced-table {
    :deep(.el-table__header) {
      th {
        background: #4b5563 !important;
        color: #f9fafb !important;
        border-bottom-color: #6b7280;
      }
    }

    :deep(.el-table__cell) {
      border-bottom-color: #4b5563;
    }
  }

  .masked-id {
    background: #4b5563;
    color: #d1d5db;
  }

  .avatar-placeholder {
    background: rgba(96, 165, 250, 0.1);
    color: #60a5fa;
  }

  .dialog-table-container,
  .dialog-pagination {
    background: #374151;
  }

  .customer-name-link {
    color: #60a5fa;

    &:hover {
      color: #93c5fd;
    }
  }
}
</style>
